#include <signal.h>
#include <unistd.h>
#include <iostream>

using namespace std;


void PrintPending(sigset_t pending)
{
    for (int i = 31; i >= 1; i--)
    {
        if (sigismember(&pending, i))
            cout << "1";
        else
            cout << "0";
    }

    cout << endl << endl;
}

int main()
{
    sigset_t bset, oset;
    sigset_t pending;
    sigemptyset(&bset);
    sigemptyset(&oset);
    //填充
    sigfillset(&bset);

    sigprocmask(SIG_BLOCK, &bset, &oset);   //设置到内核


    int cnt = 0;
    while (true)
    {
        //获取pending表
        int n = sigpending(&pending);
        if (n < 0) continue;
        
        //打印pending
        PrintPending(pending);
        sleep(1);
        ++cnt;
        if (cnt > 5) 
        {   
            cout << cnt << endl;
            sigdelset(&bset, SIGINT);     //删除SIGINT信号的忽略
            sigprocmask(SIG_SETMASK, &bset, &oset);   //重新设置到内核

            //已经处理SIGINT，不会打印下面的内容
            sigpending(&pending);            //更新pending
            PrintPending(pending);
        }
    }   

    return 0;
}